<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :label-col="{ style: { width: '70px' } }">
        <a-form-item name="pyjm" label="" class="w-1/4">
          <a-input v-model:value="formState.pyjm" placeholder="姓名/助记码/卡号/手机号/身份证号/会员卡号" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <div class="flex justify-end mb-2">
        <BaseExport type="门诊" name="会员检索" code="000758" :search-params="formState">导出</BaseExport>
      </div>
      <BaseTable fill :loading="loading" column-code="000758" :data-source="tableData" bordered :pagination="pagination">
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'action'">
            <a-button type="link" size="small" @click="onClickRecharge(record)"> 充值 </a-button>
            <a-button type="link" danger size="small" @click="onClickRefund(record)"> 退还 </a-button>
          </template>
        </template>
      </BaseTable>
    </a-card>
    <!-- 充值 -->
    <ChargeModal v-model:open="chargeOpen" :br-id="rowData.brId" :business-data="rowData" @success="getData" />
    <!-- 退还 -->
    <Refund v-model:open="priceOpen" :business-data="rowData" @success="getData" />
  </div>
</template>

<script setup>
import { ref } from 'vue'
// import { message } from 'ant-design-vue'
import SearchContainer from '@/components/SearchContainer'
// import { post } from '@/utils/request'
import Refund from './components/RefundModal'
import ChargeModal from './components/ChargeModal'

const formRef = ref(null)
const formState = ref({})
const rowData = ref({})
const chargeOpen = ref(false)
const priceOpen = ref(false)
const { loading, tableData, pagination, getData } = useTable({
  url: '/common/emp/getMemberCardList',
  immediate: true,
  params: formState.value
})

// 充值
const onClickRecharge = (row) => {
  rowData.value = { ...row }
  chargeOpen.value = true
}

//退还
const onClickRefund = (row) => {
  rowData.value = { ...row }
  priceOpen.value = true
}
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
